package com.sanben.company.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sanben.common.web.domain.Result;
import com.sanben.company.data.dto.CompanyTeamDto;
import com.sanben.company.data.req.CompanyTeamReq;
import com.sanben.company.data.vo.CompanyTeamVo;
import com.sanben.company.entity.CompanyTeam;
import com.sanben.company.service.ICompanyTeamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author cyh
 * @description: 公司团队表 控制器
 * @date: 2020-08-11
 */
@RestController
@RequestMapping("/companyTeam")
@Api(tags = "公司团队表相关接口")
public class CompanyTeamController {

    @Autowired
	private ICompanyTeamService companyTeamService;

	@GetMapping("/page")
	@ApiOperation(value = "公司团队列表")
	public Result<IPage<CompanyTeamVo>> page(CompanyTeamReq req) {
		IPage<CompanyTeamVo> pages = companyTeamService.page(req);
		return Result.data(pages);
	}

	@GetMapping("/home/list")
	@ApiOperation(value = "首页-公司团队")
	public Result<List<CompanyTeam>> getHomeList() {
		List<CompanyTeam> list = companyTeamService.getHomeList();
		return Result.data(list);
	}

	@GetMapping("/answer")
	@ApiOperation(value = "解答排行榜")
	public Result<List<CompanyTeam>> answer() {
		List<CompanyTeam> pages = companyTeamService.answer();
		return Result.data(pages);
	}

	@GetMapping("/selection/companyTeam")
	@ApiOperation(value = "公司团队列表")
	public Result<IPage<CompanyTeamVo>> selectionCompanyTeam(CompanyTeamReq req) {
		IPage<CompanyTeamVo> pages = companyTeamService.selectionCompanyTeam(req);
		return Result.data(pages);
	}

	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入id")
	public Result<CompanyTeam> detail(@PathVariable Integer id) {
	    CompanyTeam detail = companyTeamService.detail(id);
		return Result.data(detail);
	}

	@PostMapping
	@ApiOperation(value = "新增", notes = "传入companyTeam")
	public Result save(@RequestBody CompanyTeamDto dto) {
		return Result.data(companyTeamService.save(dto));
	}

	@PutMapping
	@ApiOperation(value = "修改", notes = "传入companyTeam")
	public Result update(@RequestBody CompanyTeamDto dto) {
		return Result.data(companyTeamService.updateById(dto));
	}

	@DeleteMapping("/{ids}")
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public Result remove(@PathVariable List<Integer> ids) {
		return Result.data(companyTeamService.deleteLogic(ids));
	}

}
